cmake_minimum_required(VERSION 3.5)
project(deepdetector)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

# if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
#   add_compile_options(-Wall -Wextra -Wpedantic)
# endif()

# CUDA
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
find_package(CUDA) 
find_package(OpenVINO)
find_library(TRT nvinfer)

if(CUDA_FOUND AND EXISTS ${TRT})
  message(WARNING "DEEPDETECTOR BACKEND_TRT")
  add_definitions(-DBACKEND_TRT)
  include_directories(/usr/local/cuda/include)
  link_directories(/usr/local/cuda/lib64)
  set(BACKEND_LIBS 
      nvinfer 
      cudart
      ${CUDA_npp_LIBRARY} 
      ${CUDA_nppc_LIBRARY} 
      ${CUDA_nppi_LIBRARY}
      ${CUDA_npps_LIBRARY}
      )
endif()
if(OpenVINO_FOUND)
  message(WARNING "DEEPDETECTOR BACKEND_OV")
  add_definitions(-DBACKEND_OV)
  set(BACKEND_LIBS 
      openvino::runtime
      ) 
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(libbase REQUIRED)
find_package(armor REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(base_interfaces REQUIRED)
find_package(message_filters REQUIRED)



include_directories(include)

#component所用cmake
add_library(deep_detector_component SHARED
 src/DeepDetector.cpp
 src/RosDeepDetector.cpp
)

add_definitions(-DDEEP_CFG="${CMAKE_CURRENT_LIST_DIR}/config/DeepDetector.yaml")
add_definitions(-DMODEL_DIR="${CMAKE_CURRENT_LIST_DIR}/model/")
add_definitions(-DARMOR_CFG="${CMAKE_CURRENT_LIST_DIR}/config/ArmorDetector.yaml")

target_link_libraries(deep_detector_component 
                      ${BACKEND_LIBS}
                      )

ament_target_dependencies(deep_detector_component
  "libbase"
  "base_interfaces"
  "cv_bridge"
  "rclcpp_components"
  "armor"
  "message_filters"
)



install(TARGETS 
  deep_detector_component
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin)

rclcpp_components_register_nodes(deep_detector_component "wmj::DeepDetector_Node")


install(DIRECTORY launch config
  DESTINATION share/${PROJECT_NAME})

ament_package()
